const { DataTypes } = require("sequelize");
const { sequelize } = require("../dbConnect");

// 活动表
const Activity = sequelize.define('activities', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: "活动ID"
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: "活动标题"
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: "活动描述"
  },
  poster: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: "活动海报"
  },
  start_time: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: "开始时间"
  },
  end_time: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: "结束时间"
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'ended'),
    defaultValue: 'active',
    comment: "活动状态"
  },
  participant_count: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: "参与人数"
  },
  rules: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: "活动规则"
  },
  prizes: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: "奖品信息"
  }
}, {
  tableName: 'activities'
});

// 轮播图表
const Banner = sequelize.define('banners', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: "轮播图ID"
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: "标题"
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: "描述"
  },
  image: {
    type: DataTypes.STRING(500),
    allowNull: false,
    comment: "图片URL"
  },
  link: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: "跳转链接"
  },
  sort: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: "排序"
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    defaultValue: 'active',
    comment: "状态"
  }
}, {
  tableName: 'banners'
});

module.exports = {
  Activity,
  Banner
};
